package CSDN.hzh22_7.test_2;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @Description:
 * @Author: Hanzao
 * @Date: 2022/07/24/22:17
 */
public class second_hzh {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        String str_0 = scan.nextLine();
        String[] line_list_0 = str_0.trim().split(" ");
        ArrayList<Integer> arr_temp = new ArrayList<>();
        for (int i = 0; i < line_list_0.length; i++) {
            arr_temp.add(Integer.parseInt(line_list_0[i]));
        }


        int m = arr_temp.get(0);
        int n = arr_temp.get(1);


        ArrayList<ArrayList> vector = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            String str_2 = scan.nextLine();
            String[] line_list_2 = str_2.trim().split(" ");
            ArrayList<Integer> temp_2 = new ArrayList<>();
            for (int j = 0; j < line_list_2.length; j++) {
                temp_2.add(Integer.parseInt(line_list_2[j]));
            }
            vector.add(temp_2);
        }


        scan.close();

        int result = solution(m, n, vector);

        System.out.println(result);

    }

    public static int solution(int m, int n, ArrayList<ArrayList> vector) {
        int result = 0;

        // TODO: 请在此编写代码
        for(int i=0;i<vector.size();i++){
            List<Integer> list = vector.get(i);
            long max = list.get(0);
            long sum = 0;

            for (int k = 0; k < list.size(); k++) {
                sum += list.get(k);
                if (sum <= list.get(k)) {
                    sum = list.get(k);
                }
                if (sum > max) {
                    max = sum;
                }
            }
            result += max;

        }

        return result;
    }
}
